﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Net;
using System.IO;
using CCWin;
using Newtonsoft.Json;
using LitJson;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;

namespace weiqijiance.联网通信协议
{
    public class LWzkyt : LWbass
    {
        public LWzkyt()
        {
            objdb = new 数据库操作.DBweiqi();
        }
        public class RootObject
        {
            public string result { get; set; }
            public string sqm { get; set; }
            public string err { get; set; }
            public string info { get; set; }
        }

        public class ZRootObject
        {
            public string result { get; set; }
            public string err { get; set; }
            public List<中科宇图.OBDCL> info { get; set; }
        }
        public string lineCode = "";
        string ssqm = "";
        public LWzkyt(string code)
        {
            lineCode = code;
            ssqm = getsqm();
            if (!getbbh("v2.1"))
            {
                MessageBox.Show("版本号错误，请更新工控软件");
            }
        }
        public string getwebservice(string jklx, string svalue)
        {
            //string sjieguo = "{\"result\":\"1\",\"err\":\"0\"}";
            ////RootObject rb = JsonConvert.DeserializeObject<RootObject>(sjieguo);
            //Trace.WriteLine(jklx + ":" + svalue);
            //Trace.WriteLine(jklx + ":" + sjieguo);
            //m_mainform.baocunriji(jklx, svalue);
            //m_mainform.baocunriji(jklx + "返回结果", sjieguo);
            //return sjieguo;
//////////////////////////////测试使用
            string jieguo = "";
            WebReferenceZKYT.DeviceSwapIfaceImplService m_vesd = new WebReferenceZKYT.DeviceSwapIfaceImplService();
            jieguo = m_vesd.jdcjk(ssqm, jklx, svalue);
            Trace.WriteLine(jklx + ":" + svalue);
            Trace.WriteLine(jklx + ":" + jieguo);
            m_mainform.baocunriji(jklx, svalue);
            m_mainform.baocunriji(jklx + "返回结果", jieguo);
            return jieguo;
        }
        public string getsqm()//获取授权码
        {
//            return "12345";
//////////////////测试使用
            WebReferenceZKYT.DeviceSwapIfaceImplService m_vesd = new WebReferenceZKYT.DeviceSwapIfaceImplService();
            string jieguo = m_vesd.getSqm(lineCode);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            ssqm = rb.sqm;
            return rb.sqm;
        }

        public bool getbbh(string bbh)//工控版本号
        {
            JsonData value = new LitJson.JsonData();
            value["bbh"] = bbh;
            string svalue = value.ToJson();

            string jieguo = getwebservice("BBH1", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
                return false;
            }
            else
            {
                return true;
            }
        }

        public override string JCZT(string szt)
        {
            string jieguo = getwebservice("JCZT", "{}");
            中科宇图.JCZT rb = JsonConvert.DeserializeObject<中科宇图.JCZT>(jieguo);

            string jcff = "";
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
                if (rb.jczt.Contains("1"))
                {

                    if (rb.jcff.Contains("1"))
                    {
                        jcff = "双怠速";
                    }
                    else if (rb.jcff.Contains("2"))
                    {
                        jcff = "稳态";
                    }
                    else if (rb.jcff.Contains("4"))
                    {
                        jcff = "加载";
                    }
                    else if (rb.jcff.Contains("5"))
                    {
                        jcff = "不透";
                    }
                }
                else if (rb.jczt.Contains("0"))
                {
                    //MessageBox.Show("等待检测");
                }

            }

            return jieguo;
        }//检测状态
        public override string OBDJC()
        {
            JsonData value = new LitJson.JsonData();
            value["jczbh"] = lineCode;
            string svalue = value.ToJson();
            string jieguo = getwebservice("OBD4", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            return jieguo;
        }//OBD检测人员

        public void getcheliangCS()//
        {
            string lsh = "";
            string sjson = OBDDJ();
            ZRootObject rbobd = JsonConvert.DeserializeObject<ZRootObject>(sjson);
            if (!rbobd.result.Contains("1"))
            {
                MessageBox.Show(rbobd.err);
            }
            else
            {
                中科宇图.OBDCL sobdcl = new 中科宇图.OBDCL();
                foreach (中科宇图.OBDCL obj in rbobd.info)
                {
                    sobdcl.ywid = obj.ywid;
                    sobdcl.cphm = obj.cphm;
                    sobdcl.cpys = obj.cpys;
                    sobdcl.vin = obj.vin;
                    sobdcl.clxh = obj.clxh;
                    sobdcl.fdjxh = obj.fdjxh;
                    sobdcl.isok = obj.isok;
                    sobdcl.fueltype = obj.fueltype;
                    sobdcl.ccrq = obj.ccrq;
                    sobdcl.isnewcar = obj.isnewcar;
                    sobdcl.zdzzl = obj.zdzzl;

                    string sql = string.Format(@"select *  from zkOBD where yewid='{0}' and cphm='{1}'", sobdcl.ywid, sobdcl.cphm);
                    DataTable dt = objdb.GetTable(sql);
                    if (dt.Rows.Count < 1)
                    {
                        sql = string.Format(@"insert into zkOBD (yewid,cphm,cpys,vin,clxh,fdjxh,isok,fueltype) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                            sobdcl.ywid, sobdcl.cphm, sobdcl.cpys, sobdcl.vin, sobdcl.clxh, sobdcl.fdjxh, sobdcl.isok, sobdcl.fueltype);
                    }
                    else
                    {
                        sql = string.Format(@"update zkOBD set cpys='{0}',vin='{1}',clxh='{2}',fdjxh='{3}',isok='{4}',fueltype='{5}'where yewid='{6}'and cphm='{7}'",
                          sobdcl.cpys, sobdcl.vin, sobdcl.clxh, sobdcl.fdjxh, sobdcl.isok, sobdcl.fueltype, sobdcl.ywid, sobdcl.cphm);
                    }
                    objdb.InsertDB(sql);
                    //////////----------------------------------------------------------------------------------------------------------------////////////////
                    sql = string.Format("select * from clxxex where cphm='{0}' and rllx='{1}'", sobdcl.cphm, sobdcl.fueltype);
                    dt = objdb.GetTable(sql);
                    if (dt.Rows.Count < 1)
                    {
                        sql = string.Format(@"insert into clxxex(cphm,rllx,jcwc,jczt)values('{0}','{1}','0','请上传OBD数据')", sobdcl.cphm, sobdcl.fueltype);
                        
                    }
                    else
                    {

                        sql = string.Format(@"update clxxex set 
zdzzl='{2}',jzzl='{3}',edgl='{4}',edzs='{5}',bsqxs='{6}',hplb='{7}',jqfs='{8}',gyfs='{9}',hclzz='{10}',sfyobd='{11}',
obdjl='{12}',xzlx='{13}',dsco='{14}',dshc='{15}',gdsco='{16}',gdshc='{17}',glkqxsq='{18}',glkqxsz='{19}',co5025='{20}',
hc5025='{21}',no5025='{22}',co2540='{23}',hc2540='{24}',no2540='{25}',co='{26}',hc='{27}',nox='{28}',gxsxs='{29}',
dyhw='{30}',lgmhd='{31}',jcwc='0',jczt='请上传OBD数据' where cphm='{0}' and rllx='{1}'",
sobdcl.cphm,
sobdcl.fueltype,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"");
                    }
                    objdb.InsertDB(sql);

                    string ssqlsh = string.Format("select * from clxxex where cphm='{0}' and rllx='{1}'", sobdcl.cphm, sobdcl.fueltype);
                    DataTable dt1 = objdb.GetTable(ssqlsh);
                    if (dt1.Rows.Count > 0)
                    {
                        lsh = dt1.Rows[0]["clxxid"].ToString().Trim();
                    }


                    string sqlAPPs = string.Format("select * from ASMData where PLATE_ID='{0}'and PCLASS_ID='{1}'", sobdcl.cphm, sobdcl.cpys.Contains("蓝") ? "02" : "01");
                    DataTable dtapp = objdb.GetTable(sqlAPPs);
                    if (dtapp.Rows.Count < 1)
                    {
                        sqlAPPs = string.Format("insert into ASMData (PLATE_ID,PCLASS_ID,ITERAT ,LOGINDATE,ASM_JYLSH) values ('{0}','{1}','1','{2}','{3}')", sobdcl.cphm, sobdcl.cpys.Contains("蓝") ? "02" : "01", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), lsh);
                        objdb.InsertDB(sqlAPPs);

                    }
                    else
                    {
                        sqlAPPs = string.Format("update ASMData set ASM_JYLSH='{0}',ITERAT=1,LOGINDATE='{1}' where  PLATE_ID='{2}'and PCLASS_ID='{3}'", lsh, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), sobdcl.cphm, sobdcl.cpys.Contains("蓝") ? "02" : "01");
                        objdb.InsertDB(sqlAPPs);
                    }
                }



                //中科宇图.OBDCL sobdcl = JsonConvert.DeserializeObject<中科宇图.OBDCL>(sjson);

            }

            //
            string json = getwebservice("CLXX", "{}");
            中科宇图.CLXX rb = JsonConvert.DeserializeObject<中科宇图.CLXX>(json);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
                //JArray jlist = JArray.Parse(json);
                //foreach (var item in jlist)
                {
                    中科宇图.CLXX yjhj03 = new 中科宇图.CLXX();
                    yjhj03.cphm = rb.cphm.ToString().Trim();//item["cphm"].ToString().Trim();
                    yjhj03.hplb = rb.hplb.ToString().Trim();//item["hplb"].ToString().Trim();
                    yjhj03.zdzzl = rb.zdzzl.ToString().Trim();//item["zdzzl"].ToString().Trim();
                    yjhj03.jzzl = rb.jzzl.ToString().Trim();//item["jzzl"].ToString().Trim();
                    yjhj03.edgl = rb.edgl.ToString().Trim();//item["edgl"].ToString().Trim();
                    yjhj03.edzs = rb.edzs.ToString().Trim();//item["edzs"].ToString().Trim();
                    yjhj03.bsqxs = rb.bsqxs.ToString().Trim();//item["bsqxs"].ToString().Trim();
                    yjhj03.rllx = rb.rllx.ToString().Trim();//item["rllx"].ToString().Trim();
                    yjhj03.jqfs = rb.jqfs.ToString().Trim();//item["jqfs"].ToString().Trim();
                    yjhj03.gyfs = rb.gyfs.ToString().Trim();//item["gyfs"].ToString().Trim();
                    yjhj03.hclzz = rb.hclzz.ToString().Trim();//item["hclzz"].ToString().Trim();
                    yjhj03.sfyobd = rb.sfyobd.ToString().Trim();//item["sfyobd"].ToString().Trim();
                    yjhj03.obdjl = rb.obdjl.ToString().Trim();// item["obdjl"].ToString().Trim();
                    yjhj03.xzlx = rb.xzlx.ToString().Trim(); //item["xzlx"].ToString().Trim();
                    try
                    {
                        yjhj03.dsco = rb.dsco.ToString().Trim();//item["dsco"].ToString().Trim();
                        yjhj03.dshc = rb.dshc.ToString().Trim();//item["dshc"].ToString().Trim();
                        yjhj03.gdsco = rb.gdsco.ToString().Trim();//item["gdsco"].ToString().Trim();
                        yjhj03.gdshc = rb.gdshc.ToString().Trim();//item["gdshc"].ToString().Trim();
                        yjhj03.glkqxsq = rb.glkqxsq.ToString().Trim();//item["glkqxsq"].ToString().Trim();
                        yjhj03.glkqxsz = rb.glkqxsz.ToString().Trim(); //item["glkqxsz"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    try
                    {
                        yjhj03.co5025 = rb.co5025.ToString().Trim();//item["co5025"].ToString().Trim();
                        yjhj03.hc5025 = rb.hc5025.ToString().Trim();//item["hc5025"].ToString().Trim();
                        yjhj03.no5025 = rb.no5025.ToString().Trim();// item["no5025"].ToString().Trim();
                        yjhj03.co2540 = rb.co2540.ToString().Trim();//item["co2540"].ToString().Trim();
                        yjhj03.hc2540 = rb.hc2540.ToString().Trim();//item["hc2540"].ToString().Trim();
                        yjhj03.no2540 = rb.no2540.ToString().Trim();// item["no2540"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    try
                    {
                        yjhj03.co = rb.co.ToString().Trim();//item["co"].ToString().Trim();
                        yjhj03.hc = rb.hc.ToString().Trim();//item["hc"].ToString().Trim();
                        yjhj03.nox = rb.nox.ToString().Trim();//item["nox"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    try
                    {
                        yjhj03.gxsxs = rb.gxsxs.ToString().Trim();//item["gxsxs"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    try
                    {
                        yjhj03.dyhw = rb.dyhw.ToString().Trim();// item["dyhw"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    try
                    {
                        yjhj03.lgmhd = rb.lgmhd.ToString().Trim();//item["lgmhd"].ToString().Trim();
                    }
                    catch (Exception ex) { }

                    // string ssql = string.Format("select * from clxxex where cphm='{0}' and hplb='{1}'", yjhj03.cphm, yjhj03.hplb);
                    string ssql = string.Format("select * from clxxex where cphm='{0}' and rllx='{1}'", yjhj03.cphm, yjhj03.rllx);
                    DataTable dt = objdb.GetTable(ssql);
                    if (dt.Rows.Count < 1)
                    {
                        ssql = string.Format(@"insert into clxxex (cphm ,hplb,zdzzl,jzzl,edgl,edzs,bsqxs,rllx,jqfs,gyfs,hclzz,
sfyobd,obdjl,xzlx,dsco,dshc,gdsco,gdshc,glkqxsq,glkqxsz,co5025,hc5025,no5025,co2540,hc2540,no2540,co,hc,nox,gxsxs,dyhw,lgmhd) 
 values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',
'{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}'
,'{27}','{28}','{29}','{30}','{31}')",
    yjhj03.cphm,
    yjhj03.hplb,
    yjhj03.zdzzl,
    yjhj03.jzzl,
    yjhj03.edgl,
    yjhj03.edzs,
    yjhj03.bsqxs,
    yjhj03.rllx,
    yjhj03.jqfs,
    yjhj03.gyfs,
    yjhj03.hclzz,
    yjhj03.sfyobd,
    yjhj03.obdjl,
    yjhj03.xzlx,
    yjhj03.dsco,
    yjhj03.dshc,
    yjhj03.gdsco,
    yjhj03.gdshc,
    yjhj03.glkqxsq,
    yjhj03.glkqxsz,
    yjhj03.co5025,
    yjhj03.hc5025,
    yjhj03.no5025,
    yjhj03.co2540,
    yjhj03.hc2540,
    yjhj03.no2540,
    yjhj03.co,
    yjhj03.hc,
    yjhj03.nox,
    yjhj03.gxsxs,
    yjhj03.dyhw,
    yjhj03.lgmhd
    );
                        objdb.InsertDB(ssql);

                    }
                    else
                    {
                        //select * from clxxex where cphm='{0}' and hplb='{1}'",
                        ssql = string.Format(@"update clxxex set 
zdzzl='{2}',jzzl='{3}',edgl='{4}',edzs='{5}',bsqxs='{6}',hplb='{7}',jqfs='{8}',gyfs='{9}',hclzz='{10}',sfyobd='{11}',
obdjl='{12}',xzlx='{13}',dsco='{14}',dshc='{15}',gdsco='{16}',gdshc='{17}',glkqxsq='{18}',glkqxsz='{19}',co5025='{20}',
hc5025='{21}',no5025='{22}',co2540='{23}',hc2540='{24}',no2540='{25}',co='{26}',hc='{27}',nox='{28}',gxsxs='{29}',
dyhw='{30}',lgmhd='{31}',jcwc='0' where cphm='{0}' and rllx='{1}'",
    yjhj03.cphm,
    yjhj03.rllx,
    yjhj03.zdzzl,
    yjhj03.jzzl,
    yjhj03.edgl,
    yjhj03.edzs,
    yjhj03.bsqxs,
    yjhj03.hplb,
    yjhj03.jqfs,
    yjhj03.gyfs,
    yjhj03.hclzz,
    yjhj03.sfyobd,
    yjhj03.obdjl,
    yjhj03.xzlx,
    yjhj03.dsco,
    yjhj03.dshc,
    yjhj03.gdsco,
    yjhj03.gdshc,
    yjhj03.glkqxsq,
    yjhj03.glkqxsz,
    yjhj03.co5025,
    yjhj03.hc5025,
    yjhj03.no5025,
    yjhj03.co2540,
    yjhj03.hc2540,
    yjhj03.no2540,
    yjhj03.co,
    yjhj03.hc,
    yjhj03.nox,
    yjhj03.gxsxs,
    yjhj03.dyhw,
    yjhj03.lgmhd);
                        objdb.InsertDB(ssql);



                    }

                    //手机APP表

                    string ssqlsh = string.Format("select * from clxxex where cphm='{0}' and hplb='{1}'", yjhj03.cphm, yjhj03.hplb);
                    DataTable dt1 = objdb.GetTable(ssqlsh);
                    //if (dt1.Rows.Count > 0)
                    //{
                    //    lsh = dt1.Rows[0]["clxxid"].ToString().Trim();
                    //}


                    //string sqlAPPs = string.Format("select * from ASMData where PLATE_ID='{0}'and PCLASS_ID='{1}'", yjhj03.cphm, yjhj03.hplb);
                    //DataTable dtapp = m_mainform.GetTable(sqlAPPs);
                    //if (dtapp.Rows.Count < 1)
                    //{
                    //    sqlAPPs = string.Format("insert into ASMData (PLATE_ID,PCLASS_ID,ITERAT ,LOGINDATE,ASM_JYLSH) values ('{0}','{1}','1','{2}','{3}')", yjhj03.cphm, yjhj03.hplb, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), lsh);
                    //    m_mainform.InsertDB(sqlAPPs);

                    //}


                }

            }
        }
        public override DataTable getjilu(string shphm, string sdatestart, string sdateend, bool bbz)//获取登录车辆上线
        {
            getcheliangCS();//测试使用
            string sql;
            if (shphm == "")
            {
                sql = string.Format(@" select * from clxxex where (jcwc!=1 or jcwc is null)  order by clxxid desc");
            }
            else
            {
                sql = string.Format(@" select * from clxxex where cphm like '%%{2}%%' and (jcwc!=1 or jcwc is null)  order by clxxid desc", shphm);
            }
            string sfujianqingk = "";
            DataTable dt = objdb.GetTable(sql);
            DataTable dtref = new DataTable();
            dtref.Columns.Add("DETECT_ID");
            dtref.Columns.Add("PLATE_ID");
            dtref.Columns.Add("PCLASS_ID");
            dtref.Columns.Add("jcff");
            dtref.Columns.Add("OBD");
            dtref.Columns.Add("jccs");
            dtref.Columns.Add("zt");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dtref.NewRow();
                    dr[0] = dt.Rows[i]["clxxid"].ToString().Trim();    //填充第一列的数据 
                    dr[1] = dt.Rows[i]["cphm"].ToString().Trim();    //填充第一列的数据 
                    dr[2] = dt.Rows[i]["hplb"].ToString().Trim();    //填充第一列的数据 
                    if (dt.Rows[i]["gdsco"].ToString().Trim().Length > 0)
                    {
                        dr[3] = string.Format("双怠速法");
                    }
                    else if (dt.Rows[i]["hc5025"].ToString().Trim().Length > 0)
                    {
                        dr[3] = string.Format("ASM工况法");
                    }
                    else if (dt.Rows[i]["dyhw"].ToString().Trim().Length > 0)
                    {
                        dr[3] = string.Format("加载减速法");
                    }
                    else if (dt.Rows[i]["gxsxs"].ToString().Trim().Length > 0)
                    {
                        dr[3] = string.Format("自由加速法");
                    }
                    dr[4] = string.Format("{0}", dt.Rows[i]["sfyobd"].ToString().Trim().Contains("0") ? "否" : "是");
                    dr[6] = dt.Rows[i]["jczt"].ToString().Trim();
                    dtref.Rows.Add(dr);

                }
            }
            return dtref;
        }

        public override string  sendOBDJCJG(string yeid, string sjylsh,bool bqz)
        {

            string jyksrq = "";
            string jyjsrq = "";
            string jyy = "";
            string jyjg = "";
            string obdzdyscqy = "";
            string obdzdyxh = "";
            string vin = "";
            string obdyq = "";
            string gzjg = "";
            string tx = "";
            string txbz = "";
            string bj = "";
            string bjbz = "";
            string jxxm = "";
            string jxxmbz = "";
            string odometer = "0";
            string odomil = "0";
            string enginecalid = "";
            string enginecvn = "";
            string hclcalid = "";
            string hclcvn = "";
            string calid = "";
            string cvn = "";
            string iupr = "";
            string sgzxx = "";

            int icountwwc = 0;
            int icountgzm = 0;
            string bgoodobd = "1";
            //查询数据内容
            string sql;

            sql = string.Format(@"select * from OBD_JCJG  where jylsh ='{0}'  order by OBD_JCJG_ID desc", sjylsh);// DateTime.Now.AddDays(-30), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            DataTable dt = objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                jyksrq = dt.Rows[0]["OBD_JCJG_date"].ToString().Trim();
                jyjsrq = dt.Rows[0]["OBD_JCJG_date"].ToString().Trim();

                jyy = "";//
                jyjg = "1";
                obdzdyscqy = m_mainform.OBDqiye;
                obdzdyxh = m_mainform.OBDname;
                vin = "";
                obdyq = "EOBD";
                gzjg = "1";
                bj = "1";
                bjbz = "";

                for (int i = 0; i < 7; i++)
                {
                    if (dt.Rows[0][string.Format("OBD_JCJG_GZM{0}", i + 1)].ToString().Trim().Length > 0)
                    {
                        icountgzm++;
                        gzjg = "0";
                        bj = "0";
                        if (bjbz.Length < 1)
                        {
                            bjbz = dt.Rows[0][string.Format("OBD_JCJG_GZM{0}", i + 1)].ToString().Trim();
                        }
                        else
                        {
                            bjbz = bjbz + ";" + makeOBD1(dt.Rows[0][string.Format("OBD_JCJG_GZM{0}", i + 1)].ToString().Trim());
                            sgzxx = sgzxx + ";" + makeOBD(dt.Rows[0][string.Format("OBD_JCJG_GZM{0}", i + 1)].ToString().Trim());
                        }
                    }

                }

                tx = "1";
                txbz = "";


                jxxm = "";
                jxxmbz = "";
                for (int i = 0; i < 10; i++)
                {
                    if (dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim().Contains("未完成"))
                    {
                        icountwwc++;
                        if (jxxmbz.Length < 1)
                        {
                            jxxmbz = dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim();
                        }
                        else
                        {
                            if (dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim().Contains("催化器"))
                            {
                                jxxm = "1";
                            }
                            else if (dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim().Contains("氧传感器"))
                            {
                                jxxm = "2";
                            }
                            else if (dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim().Contains("加热"))
                            {
                                jxxm = "3";
                            }
                            else if (dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim().Contains("废气"))
                            {
                                jxxm = "4";
                            }
                            jxxm += jxxm;
                            jxxmbz = jxxmbz + dt.Rows[0][string.Format("OBD_JCJG_JXZT{0}", i + 1)].ToString().Trim();
                        }
                    }
                }
                if (jxxm.Length < 1)
                {
                    jxxm = "0";
                }
                for (int i = 0; i < 12; i++)
                {
                    if (dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim().Contains("里程表"))
                    {

                        odometer = makeOBD(dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim());

                    }
                    if (dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim().Contains("点亮后的行驶距离"))
                    {
                        odomil = makeOBD(dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim());
                    }
                    if (dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim().Contains("车辆OBD型号"))
                    {
                        obdyq = makeOBD(dt.Rows[0][string.Format("OBD_JCJG_SJL{0}", i + 1)].ToString().Trim());
                    }

                }

                if (dt.Rows[0][string.Format("OBD_JCJG_CLXX1")].ToString().Trim().Length > 0)
                {
                    enginecalid = makeOBD(dt.Rows[0]["OBD_JCJG_CLXX1"].ToString().Trim());
                }
                if (dt.Rows[0][string.Format("OBD_JCJG_CLXX2")].ToString().Trim().Length > 0)
                {
                    enginecvn = makeOBD(dt.Rows[0]["OBD_JCJG_CLXX2"].ToString().Trim());
                }
                hclcalid = "";
                hclcvn = "";
                calid = "";
                cvn = "";
                iupr = "";
                #region IUPR
                string IUPRchqwccs1 = "0";//催化器组1，NMHC 催化器监
                string IUPRchfhcs1 = "0";
                string IUPRchfhlv1 = "0";
                string IUPRchqwccs2 = "0";//催化器组2，nox催化器
                string IUPRchfhcs2 = "0";
                string IUPRchfhlv2 = "0";
                string IUPRqycgqcs1 = "0";//前氧组1，nox吸附器
                string IUPRqycgqcsfh1 = "0";
                string IUPRqycgqcslv1 = "0";
                string IUPRqycgqcs2 = "0";//前氧组2，PM 捕集器符
                string IUPRqycgqcsfh2 = "0";
                string IUPRqycgqcslv2 = "0";
                string IUPRhycgqcs1 = "0";//后氧组1，废气传感器
                string IUPRhycgqcsfh1 = "0";
                string IUPRhycgqcslv1 = "0";
                string IUPRhycgqcs2 = "0";//后氧组2，增压压力
                string IUPRhycgqcsfh2 = "0";
                string IUPRhycgqcslv2 = "0";
                string IUPREVAPcs = "0";//EVAP 汽油
                string IUPREVAPfhcs = "0";
                string IUPREVAPlv = "0";
                string IUPREGRVVTcs = "0";//EGR 和 VVT
                string IUPREGRVVTfhcs = "0";
                string IUPREGRVVTlv = "0";
                string IUPRGPFcs1 = "0";//GPF 汽油
                string IUPRGPFfhcs1 = "0";
                string IUPRGPFlv1 = "0";
                string IUPRGPFcs2 = "0";//GPF 汽油
                string IUPRGPFfhcs2 = "0";
                string IUPRGPFlv2 = "0";
                string IUPRdiercs = "0";//二次空气喷射系统监
                string IUPRdierfhcs = "0";
                string IUPRdierlv = "0";
                for (int i = 0; i < 34; i++)
                {
                    if (dt.Rows[0][string.Format("OBD_JCJG_IUPR{0}", i + 1)].ToString().Trim().Length > 0)
                    {
                        string sdata = dt.Rows[0][string.Format("OBD_JCJG_IUPR{0}", i + 1)].ToString().Trim();
                        if (sdata.Contains("副氧传感器"))
                        {
                            sdata = sdata.Replace("副氧传感器", "后氧");
                        }

                        if ((sdata.Contains("催化器监视完成次数") && sdata.Contains("组1")) ||
                            (sdata.Contains("NMHC催化器监视完成次数")))
                        {
                            IUPRchqwccs1 = makeiupr(sdata.Trim());
                        }

                        if ((sdata.Contains("催化器监视条件符合次数") && sdata.Contains("组1")) ||
                             (sdata.Contains("NMHC催化器监视条件符合次数")))
                        {
                            IUPRchfhcs1 = makeiupr(dt.Rows[0][string.Format("OBD_JCJG_IUPR{0}", i + 1)].ToString().Trim());
                        }

                        if ((sdata.Contains("催化器实际监测频率") && sdata.Contains("组1")) ||
                             (sdata.Contains("NMHC催化器实际监测频率")))
                        {
                            IUPRchfhlv1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("催化器监视完成次数") && sdata.Contains("组2")) ||
                            (sdata.Contains("NOx催化器监视完成次数")))
                        {
                            IUPRchqwccs2 = makeiupr(dt.Rows[0][string.Format("OBD_JCJG_IUPR{0}", i + 1)].ToString().Trim());
                        }

                        if ((sdata.Contains("催化器监视条件符合次数") && sdata.Contains("组2")) ||
                              (sdata.Contains("NOx催化器监视条件符合次数")))
                        {
                            IUPRchfhcs2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("催化器实际监测频率") && sdata.Contains("组2")) ||
                              (sdata.Contains("NOx催化器实际监测频率")))
                        {
                            IUPRchfhlv2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("氧传感器监视完成次数") && sdata.Contains("组1")) ||
                            (sdata.Contains("NOx吸附器监视完成次数")))
                        {
                            IUPRqycgqcs1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("氧传感器监视条件符合次数") && sdata.Contains("组1")) ||
                            (sdata.Contains("NOx吸附器监视条件符合次数")))
                        {
                            IUPRqycgqcsfh1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("氧传感器实际监测频率") && sdata.Trim().Contains("组1")) ||
                            (sdata.Contains("NOx吸附器实际监测频率")))
                        {
                            IUPRqycgqcslv1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("氧传感器监视完成次数") && sdata.Contains("组2")) ||
                            (sdata.Contains("微粒(PM)过滤器监视完成次数")))
                        {
                            IUPRqycgqcs2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("氧传感器监视条件符合次数") && sdata.Contains("组2")) ||
                            (sdata.Contains("微粒(PM)过滤器监视条件符合次数")))
                        {
                            IUPRqycgqcsfh2 = makeiupr(dt.Rows[0][string.Format("OBD_JCJG_IUPR{0}", i + 1)].ToString().Trim());
                        }

                        if ((sdata.Contains("氧传感器实际监测频率") && sdata.Contains("组2")) ||
                            (sdata.Contains("微粒(PM)过滤器实际监测频率")))
                        {
                            IUPRqycgqcslv2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧监视完成次数") && sdata.Contains("组1")) ||
                            (sdata.Contains("废气传感器监视完成次数")))
                        {
                            IUPRhycgqcs1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧监视条件符合次数") && sdata.Contains("组1")) ||
                            (sdata.Contains("废气传感器监视条件符合次数")))
                        {
                            IUPRhycgqcsfh1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧实际监测频率") && sdata.Contains("组1")) ||
                            (sdata.Contains("废气传感器实际监测频率")))
                        {
                            IUPRhycgqcslv1 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧监视完成次数") && sdata.Contains("组2")) ||
                            (sdata.Contains("增压压力监视完成次数")))
                        {
                            IUPRhycgqcs2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧监视条件符合次数") && sdata.Contains("组2")) ||
                            (sdata.Contains("增压压力监视条件符合次数")))
                        {
                            IUPRhycgqcsfh2 = makeiupr(sdata);
                        }

                        if ((sdata.Contains("后氧实际监测频率") && sdata.Contains("组2")) ||
                            (sdata.Contains("增压压力实际监测频率")))
                        {
                            IUPRhycgqcslv2 = makeiupr(sdata);
                        }

                        if (sdata.Contains("EVAP监视完成次数"))
                        {
                            IUPREVAPcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EVAP监视条件符合次数"))
                        {
                            IUPREVAPfhcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EVAP实际监测频率"))
                        {
                            IUPREVAPlv = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT监视完成次数"))
                        {
                            IUPREGRVVTcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT监视条件符合次数"))
                        {
                            IUPREGRVVTfhcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT实际监测频率"))
                        {
                            IUPREGRVVTlv = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT监视完成次数"))
                        {
                            IUPREGRVVTcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT监视条件符合次数"))
                        {
                            IUPREGRVVTfhcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("EGR和/或VVT实际监测频率"))
                        {
                            IUPREGRVVTlv = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF监视完成次数") && sdata.Contains("组1"))
                        {
                            IUPRGPFcs1 = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF监视条件符合次数") && sdata.Contains("组1"))
                        {
                            IUPRGPFfhcs1 = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF实际监测频率") && sdata.Contains("组1"))
                        {
                            IUPRGPFlv1 = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF监视完成次数") && sdata.Contains("组2"))
                        {
                            IUPRGPFcs2 = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF监视条件符合次数") && sdata.Contains("组2"))
                        {
                            IUPRGPFfhcs2 = makeiupr(sdata);
                        }

                        if (sdata.Contains("GPF实际监测频率") && sdata.Contains("组2"))
                        {
                            IUPRGPFlv2 = makeiupr(sdata);
                        }

                        if (sdata.Contains("二次空气喷射系统监视完成次数"))
                        {
                            IUPRdiercs = makeiupr(sdata);
                        }

                        if (sdata.Contains("二次空气喷射系统监视条件符合次数"))
                        {
                            IUPRdierfhcs = makeiupr(sdata);
                        }

                        if (sdata.Contains("二次空气喷射系统实际监测频率"))
                        {
                            IUPRdierlv = makeiupr(sdata);
                        }
                    }
                }
                #endregion
                if (icountwwc > 2 || icountgzm > 0)
                {
                    bgoodobd = "0";
                }

                ///
                if (bqz)
                {
                    bjbz = "";
                    sgzxx = "";
                    jxxm = "0";
                    bgoodobd = "1";
                }


                JsonData value = new LitJson.JsonData();
                value["jcrid"] = "yuanb";
                value["jcyid"] = "1571908699148_gycs";
                value["fdjcalid"] = enginecalid;
                value["fdjcvn"] = enginecvn;
                value["hclcalid"] = hclcalid;
                value["hclcvn"] = hclcvn;
                value["qtcalid"] = "";
                value["qtcvn"] = "";
                value["gzzsq"] = "1";//OBD 故障指示器 字符串 1 0 不合格，1 合格
                value["zdytxqk"] = "0";//OBD 诊断仪通讯情况 0 通讯成功，1 找不到接口，2接口损坏，3 连接后不能通讯
                value["zsqsfbdl"] = "0";//OBD 故障指示器是否被点亮
                value["gzdm"] = bjbz;//故障代码
                value["gzxx"] = sgzxx;//故障信息
                value["wwcxm"] = jxxm;//"0";//jxxm;//jxxmbz;//wwcxm 诊断就绪状态未完成项目
                value["milxslc"] = odomil;//odomil;//MIL 灯点亮后行驶里程
                value["ljxslc"] = odometer;//odometer;//车辆累计行驶里程
                value["vin"] = vin;
                value["obdyq"] = obdyq;//型式检验时的OBD 要求
                value["jgpd"] = bgoodobd;
                value["sfxyfj"] = "0";
                value["fjnr"] = "";

                DateTime datejssj = new DateTime();
                DateTime.TryParse(dt.Rows[0]["OBD_JCJG_date"].ToString(), out datejssj);

                value["jckssj"] = datejssj.ToString("yyyy-MM-dd HH:mm:ss"); ;
                value["jcjssj"] = datejssj.ToString("yyyy-MM-dd HH:mm:ss");
                string svalue = value.ToJson();



                ///iURL
                ///
                中科宇图.OBD3 var = new 中科宇图.OBD3()
                {
                    #region 失效
                                        //chq1jccs = "100",
                    //chq1fhcs = "90",
                    //chq1iupr = "0.9",
                    //chq2jccs = "100",
                    //chq2fhcs = "90",
                    //chq2iupr = "0.9",
                    //qycqq1jccs = "100",
                    //qycqq1fhcs = "90",
                    //qycqq1iupr = "0.9",
                    //qycqq2jccs = "100",
                    //qycqq2fhcs = "90",
                    //qycqq2iupr = "0.9",
                    //hycqq1jccs = "100",
                    //hycqq1fhcs = "90",
                    //hycqq1iupr = "0.9",
                    //hycqq2jccs = "100",
                    //hycqq2fhcs = "90",
                    //hycqq2iupr = "0.9",
                    //evapjccs = "100",
                    //evapfhcs = "90",
                    //evapiupr = "0.9",
                    //egrvvtjccs = "100",
                    //egrvvtfhcs = "90",
                    //egrvvtiupr = "0.9",
                    //gpf1jccs = "100",
                    //gpf1fhcs = "90",
                    //gpf1iupr = "0.9",
                    //gpf2jccs = "100",
                    //gpf2fhcs = "90",
                    //gpf2iupr = "0.9",
                    //eckqpsxtjccs = "100",
                    //eckqpsxtfhcs = "90",
                    //eckqpsxtiupr = "0.9",
                    #endregion
                    chq1jccs = IUPRchqwccs1,
                    chq1fhcs = IUPRchfhcs1,
                    chq1iupr = IUPRchfhlv1,
                    chq2jccs = IUPRchqwccs2,
                    chq2fhcs = IUPRchfhcs2,
                    chq2iupr = IUPRchfhlv2,
                    qycqq1jccs = IUPRqycgqcs1,
                    qycqq1fhcs = IUPRqycgqcsfh1,
                    qycqq1iupr = IUPRqycgqcslv1,
                    qycqq2jccs = IUPRqycgqcs2,
                    qycqq2fhcs = IUPRqycgqcsfh2,
                    qycqq2iupr = IUPRqycgqcslv2,
                    hycqq1jccs = IUPRhycgqcs1,
                    hycqq1fhcs = IUPRhycgqcsfh1,
                    hycqq1iupr = IUPRhycgqcslv1,
                    hycqq2jccs = IUPRhycgqcs2,
                    hycqq2fhcs = IUPRhycgqcsfh2,
                    hycqq2iupr = IUPRhycgqcslv2,
                    evapjccs = IUPREVAPcs,
                    evapfhcs = IUPREVAPfhcs,
                    evapiupr = IUPREVAPlv,
                    egrvvtjccs = IUPREGRVVTcs,
                    egrvvtfhcs = IUPREGRVVTfhcs,
                    egrvvtiupr = IUPREGRVVTlv,
                    gpf1jccs = IUPRGPFcs1,
                    gpf1fhcs = IUPRGPFfhcs1,
                    gpf1iupr = IUPRGPFlv1,
                    gpf2jccs = IUPRGPFcs2,
                    gpf2fhcs = IUPRGPFfhcs2,
                    gpf2iupr = IUPRGPFlv2,
                    eckqpsxtjccs = IUPRdiercs,
                    eckqpsxtfhcs = IUPRdierfhcs,
                    eckqpsxtiupr = IUPRdierlv,
                    jckssj = datejssj.ToString("yyyy-MM-dd HH:mm:ss"),
                    jcjssj = datejssj.ToString("yyyy-MM-dd HH:mm:ss")
                };
                string svalueiu = JsonConvert.SerializeObject(var);
                string sjieguoiu = getobd(yeid, "OBD3", svalueiu);

                string jieguo = getobd(yeid, "OBD1", svalue);
                RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

                string sqlzt = string.Format("select * from clxxex where clxxid={0}", int.Parse(sjylsh));
                DataTable dt1 = objdb.GetTable(sqlzt);
                if (dt1.Rows.Count > 0)
                {
                    sqlzt = string.Format(@"update clxxex set jczt='OBD数据上传完成' where clxxid={0}", int.Parse(sjylsh));
                    objdb.InsertDB(sqlzt);
                }


                if (!rb.result.Contains("1"))
                {
                    MessageBox.Show(rb.err);
                }
                else
                {
                    MessageBox.Show("OBD数据上传成功，请进行线上检测");
                }
            }
            else
            {

                MessageBox.Show("OBD数据位空,重新完成OBD检查");
            }
            return "";

        }//OBD结果

        public string getobd(string yeid, string jklx, string svalue)
        {
            //string sjieguo = "{\"result\":\"1\",\"err\":\"0\"}";
            ////RootObject rb = JsonConvert.DeserializeObject<RootObject>(sjieguo);
            //Trace.WriteLine(jklx + ":" + svalue);
            //Trace.WriteLine(jklx + ":" + sjieguo);
            //m_mainform.baocunriji(jklx, svalue);
            //m_mainform.baocunriji(jklx + "返回结果", sjieguo);
            //return sjieguo;
            ////测试
            WebReferenceZKYT.DeviceSwapIfaceImplService m_vesd = new WebReferenceZKYT.DeviceSwapIfaceImplService();
            string jieguo = m_vesd.jdcjk(yeid, jklx, svalue);
            Trace.WriteLine(jklx + ":" + svalue);
            Trace.WriteLine(jklx + ":" + jieguo);
            m_mainform.baocunriji(jklx, svalue);
            m_mainform.baocunriji(jklx + "返回结果", jieguo);
            return jieguo;

        }

        public string makeOBD(string obd)
        {
            string shuoming = "";
            string shuoming2 = string.Empty;
            string[] a = Regex.Split(obd, ",", RegexOptions.IgnoreCase);
            //  for (int i = 0; i < a.Length; i++)
            if (a.Length > 1)
            {
                shuoming = a[0];
                shuoming2 = a[1];
            }

            return shuoming2;
        }
        public string makeOBD1(string obd)
        {
            string shuoming = "";
            string shuoming2 = string.Empty;
            string[] a = Regex.Split(obd, ",", RegexOptions.IgnoreCase);
            //  for (int i = 0; i < a.Length; i++)
            if (a.Length > 1)
            {
                shuoming = a[0];
                shuoming2 = a[1];
            }

            return shuoming;
        }

        public string makeiupr(string sdata)
        {
            string sjieguo = "0,0,0";
            var jg = sdata.Split(',');
            sjieguo = jg[jg.Length - 1];
            return sjieguo;
        }

        public override void getstandxz(string slsh)//获取限值
        {
            string sql;

            sql = string.Format(@"Select *  from clxxex where  clxxid={0}", slsh);

            DataTable dt = objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                float.TryParse(dt.Rows[0]["hc5025"].ToString().Trim(), out m_mainform.HCEL5025);
                float.TryParse(dt.Rows[0]["co5025"].ToString().Trim(), out m_mainform.COEL5025);
                float.TryParse(dt.Rows[0]["no5025"].ToString().Trim(), out m_mainform.NOEL5025);
                float.TryParse(dt.Rows[0]["hc2540"].ToString().Trim(), out m_mainform.HCEL2540);
                float.TryParse(dt.Rows[0]["co2540"].ToString().Trim(), out m_mainform.COEL2540);
                float.TryParse(dt.Rows[0]["no2540"].ToString().Trim(), out m_mainform.NOEL2540);

                float.TryParse(dt.Rows[0]["dsco"].ToString().Trim(), out m_mainform.LICOL);
                float.TryParse(dt.Rows[0]["dshc"].ToString().Trim(), out m_mainform.LIHCL);
                float.TryParse(dt.Rows[0]["gdsco"].ToString().Trim(), out m_mainform.HICOL);
                float.TryParse(dt.Rows[0]["gdshc"].ToString().Trim(), out m_mainform.HIHCL);

                float.TryParse(dt.Rows[0]["gxsxs"].ToString().Trim(), out m_mainform.TypeApprovalLimits);
                float.TryParse(dt.Rows[0]["dyhw"].ToString().Trim(), out m_mainform.noxlimit);
                float.TryParse(dt.Rows[0]["gxsxs"].ToString().Trim(), out m_mainform.InspectionLimits);


            }
            else
            {

            }
        }


        public override string start(string sjylsh, string stime, string sycy, string sczy, bool bqz)
        {
            return "成功";
        }

        public virtual bool stop(string sjylsh, string jyjg)
        {
            return true;
        }

        public override void insertjcwc(string slsh)//检测完成标志
        {
            string sqlxzxx = string.Format(@"update clxxex set jcwc=1 where clxxid={0} ", slsh);
            objdb.InsertDB(sqlxzxx);
        }

        public override string sjuploadASM(string businessId, model.ASM.ASMsj objasmsj, model.ASM.ASMgcsj objasmgcsj, model.ASM.ASMobdgcsj objasmobd, int ics)
        {
            string timeEnd = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            bool bgood = false;
            if ((!objasmsj.b2540 && (objasmsj.iHC25 > m_mainform.HCEL5025 || objasmsj.fCO25 > m_mainform.COEL5025 || objasmsj.iNO25 > m_mainform.NOEL5025)) ||
               objasmsj.iHC40 > m_mainform.HCEL2540 || objasmsj.fCO40 > m_mainform.COEL2540 || objasmsj.iNO40 > m_mainform.NOEL2540)
            {
                bgood = false;
            }
            else
            {
                bgood = true;
            }
            /*      if (objasmsj.iHC25 > m_mainform.HCEL5025 ||
                       objasmsj.iHC40 > m_mainform.HCEL2540 ||
                                       objasmsj.fCO25 > m_mainform.COEL5025 ||
                                       objasmsj.fCO40 > m_mainform.COEL2540 ||
                                       objasmsj.iNO25 > m_mainform.NOEL5025 ||
                                       objasmsj.iNO40 > m_mainform.NOEL2540)
                  {
                      bgood = false;
                  }
                  else
                  {
                      bgood = true;
                  }
                  */
            float fcs5025 = 0;//平均车速
            float fcs2540 = 0;
            int icount = 0;
            for (int i = 0; i < objasmgcsj.m_SpeedGCSJ25.Length; i++)
            {
                fcs5025 += objasmgcsj.m_SpeedGCSJ25[i];
                icount++;
            }
            icount = 0;
            for (int j = 0; j < objasmgcsj.m_SpeedGCSJ40.Length; j++)
            {
                fcs2540 += objasmgcsj.m_SpeedGCSJ40[j];
                icount++;
            }
            fcs5025 = fcs5025 / ((float)icount);//平均车速
            fcs2540 = fcs2540 / ((float)icount);

            if (!objasmsj.b2540 && !bgood)
            {
                objasmsj.iHC40 = -9;
                objasmsj.fCO40 = -9.00f;
                objasmsj.iNO40 = -9;
            }
            var objjcjg = new 中科宇图.WT01()
            {
                hc5025 = objasmsj.iHC25.ToString("0.00"),
                co5025 = objasmsj.fCO25.ToString("0.00"),
                no5025 = objasmsj.iNO25.ToString("0.00"),

                fdjzs5025 = objasmsj.fdjzs5025.ToString(),
                fdjyw5025 = objasmsj.fdjyw5025.ToString("0.00"),
                cs5025 = fcs5025.ToString("0.00"),
                jzzgl5025 = objasmsj.jzzgl5025.ToString("0.00"),


                hc2540 = objasmsj.iHC40.ToString("0.00"),
                co2540 = objasmsj.fCO40.ToString("0.00"),
                no2540 = objasmsj.iNO40.ToString("0.00"),
                fdjzs2540 = objasmsj.fdjzs2540.ToString(),
                fdjyw2540 = objasmsj.fdjyw2540.ToString("0.00"),
                cs2540 = fcs2540.ToString("0.00"),
                jzzgl2540 = objasmsj.jzzgl2540.ToString("0.00"),
                wd = objasmsj.fwendu.ToString("0.00"),
                sd = objasmsj.fshidu.ToString("0.00"),
                qy = objasmsj.fdaqiya.ToString("0.00"),
                jgpd = bgood ? "1" : "0",
                jckssj = TESTASM.timeStart,
                jcjssj = timeEnd
            };
            string svalue = JsonConvert.SerializeObject(objjcjg);
            string jieguo = getwebservice("WT01", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            stop(businessId,"");
            return "1";
        }
        public override string sjuploadSDS(string businessId, model.SDS.SDSsj objsj, model.SDS.SDSgcsj objgcsj, model.ASM.ASMobdgcsj objasmobd)
        {
            int ilandapd = 1;
            if (objsj.fLAMDAG > 1.05 || objsj.fLAMDAG < 0.95)
            {
                ilandapd = 0;
                objsj.bgood = false;
            }
            string lamda = objsj.fLAMDAG.ToString("0.000");
            var objsdsjcjg = new 中科宇图.SDS1()
            {
                dsfdjzs = objsj.dsfdjzs.ToString(),
                gdsfdjzs = objsj.gdsfdjzs.ToString(),
                codds = objsj.fCOD.ToString("0.00"),
                hcdds = objsj.iHCD.ToString("0.00"),
                cogds = objsj.fCOG.ToString("0.00"),
                hcgds = objsj.iHCG.ToString("0.00"),
                glkqxs = objsj.fLAMDAG.ToString("0.00"),
                jyyw = objsj.jyyw.ToString("0.00"),
                wd = objsj.fwendu.ToString("0.00"),
                sd = objsj.fshidu.ToString("0.00"),
                qy = objsj.fdaqiya.ToString("0.00"),
                jgpd = objsj.bgood ? "1" : "0",
                jckssj = TESTSDS.timeStart,
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            string svalue = JsonConvert.SerializeObject(objsdsjcjg);

            string jieguo = getwebservice("SDS1", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            stop(businessId,"");
            return "1";
        }

        public override string sjuploadZYJS(string businessId, model.ZYJS.ZYJSsj objsj, model.ZYJS.ZYJSgcsj objgcsj, model.LUG.LUGobdgcsj objobdgcsj)
        {
            var objjcjg = new 中科宇图.BTG1()
            {
                ydz1 = objsj.SK1.ToString("0.00"),
                ydz2 = objsj.SK2.ToString("0.00"),
                ydz3 = objsj.SK3.ToString("0.00"),
                dszs = objsj.m_SKTurn.ToString(),
                wd = objsj.fwendu.ToString("0.00"),
                sd = objsj.fshidu.ToString("0.00"),
                qy = objsj.fdaqiya.ToString("0.00"),
                jgpd = objsj.fSKPJ > m_mainform.InspectionLimits ? "0" : "1",
                jckssj = TESTZYJS.timeStart,
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            string svalue = JsonConvert.SerializeObject(objjcjg);

            string jieguo = getwebservice("BTG1", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            stop(businessId,"");
            return "1";
        }

        public override string  sjuploadLUG(string businessId, model.LUG.LUGsj objsj, model.LUG.LUGgcsj objgcsj, model.LUG.LUGobdgcsj objobdgcsj)
        {
            var objyjsj = new 中科宇图.JZ01()
            {
                ydz100 = objsj.m_sk100.ToString("0.00"),
                nox100 = objsj.nox100.ToString(),
                zs100 = objsj.zs100.ToString(),
                zgxsd100 = objsj.zgxsd100.ToString(),
                lbgl100 = objsj.lbgl100.ToString("0.00"),
                ydz80 = objsj.m_sk80.ToString("0.00"),
                nox80 = objsj.m_sno80.ToString("0"),
                zs80 = objsj.zs80.ToString(),
                zgxsd80 = objsj.zgxsd80.ToString(),
                lbgl80 = objsj.lbgl80.ToString("0.00"),
                sczdlbgl = objsj.sczdlbgl.ToString("0.00"),
                xzzdlbgl = objsj.xzzdlbgl.ToString("0.00"),
                zdlbglxzxs = objsj.zdlbglxzxs.ToString("0.00"),
                zdlbglsd = objsj.maxpowerspeed.ToString("0.00"),
                zdlbglfdjzs = objsj.zdlbglfdjzs.ToString(),
                fdjdszs = objsj.fdjdszs.ToString(),
                zdlbgljsgtxsd = objsj.maxpowerspeed.ToString("0.00"),
                zdlbglsjxsd = objsj.zdlbglsjxsd.ToString("0.00"),
                wd = objsj.fwendu.ToString("0.00"),
                sd = objsj.fshidu.ToString("0.00"),
                qy = objsj.fdaqiya.ToString("0.00"),
                jgpd = objsj.bgood ? "1" : "0",
                jckssj = TESTLUG.timeStart,
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(objyjsj);
            string jieguo = getwebservice("JZ01", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            stop(businessId,"");
            return "1";
        }


        public override string zmgcsjlug(string businessId, model.LUG.LUGgcsjZM objgcsj)
        {
            //            工况类型:
            //0-功率扫描中、1-恢复到100%VelMaxHP过程、2-100%VelMaxHP点检验过程、
            //            3-恢复到80%VelMaxHP过程、4-80%VelMaxHP点检验过程、5-减载停车
            //            0(功率扫描中),
            //1(恢复到100%VelMaxHP 过程),
            //2(100%VelMaxHP 点检验),
            //3（恢复到80%VelMaxHP 点过程）
            //4(80%VelMaxHP 点检验)
            //sdjzxs 湿度校正系数  没增加，写死1
            var objyjsj = new 中科宇图.JZ02()
            {
                jcsxh = objgcsj.iobd.ToString("0"),
                gklx = objgcsj.GKLX.ToString("0"),
                cgjzh = objgcsj.fPower.ToString("0.00"),
                cs = objgcsj.m_fspeed.ToString("0.00"),
                fdjzs = objgcsj.ftrun.ToString("0"),
                nl = objgcsj.fnj.ToString("0.00"),
                nj = objgcsj.fnj.ToString("0.00"),
                wd = objgcsj.m_fWenDu.ToString("0.00"),
                qy = objgcsj.m_fYaLi.ToString("0.00"),
                sd = objgcsj.m_fShiDu.ToString("0.00"),
                glxzxs = (double.IsInfinity(objgcsj.fpowerK) || double.IsNaN(objgcsj.fpowerK) ? 1 : objgcsj.fpowerK).ToString("0.00"),
                sdjzxs = "1",//objgcsj.dsdxzxs.ToString("0.00"),question
                lbgl = objgcsj.fPower.ToString("0.00"),
                gxsxs = objgcsj.m_fsk.ToString("0.00"),
                noxnd = objgcsj.m_fnosk.ToString("0"),
                co2nd = objgcsj.m_fco2sk.ToString("0.00"),
                dqsjc = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(objyjsj);
            string jieguo = getwebservice("JZ02", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                //       MessageBox.Show(rb.err);
            }
            else
            {
            }

            return rb.result.ToString();
        }


        public override string zmgcsjzyjs(string businessId, model.ZYJS.ZYJSgcsjZM objgcsj)
        {
//            工况类型:
//1为第一次，2为第二次，以此类推

//            0（吹拂阶段）
//第 29 页
//1（第一次），
//2（第二次），
//3（第三次）
            var objyjsj = new 中科宇图.BTG2()
            {
                jcsxh = objgcsj.iobd.ToString("0"),
                gklx = objgcsj.GKLX.ToString("0"),
                ydz = objgcsj.m_fsk.ToString("0.00"),
                fdjzs = objgcsj.fZS.ToString("0"),
                wd = objgcsj.m_fWenDu.ToString("0.00"),
                sd = objgcsj.m_fShiDu.ToString("0.00"),
                qy = objgcsj.m_fYaLi.ToString("0.00"),
                dqsjc = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(objyjsj);
            string jieguo = getwebservice("BTG02", svalue);

            return "1";
        }

        public override string zmgcsjasm(string businessId, model.ASM.ASMgcsjZM objgcsj)
        {
           // 0-检验准备、
           // 1-5025加速过程、2-5025快速工况过程、3-5025工况过程、
           // 4-2540加速过程、5-2540快速工况过程、6-2540工况过程、7-减速过程 
            //-----

            //--------

            //if (objgcsj.GKLX == "1")
            //{
            //    objgcsj.GKLX = "1";
            //}
            //else if (objgcsj.GKLX == "0")
            //{
            //    objgcsj.GKLX = "0";
            //}
            //else if (objgcsj.GKLX == "2")
            //{
            //    objgcsj.GKLX = "2";
            //}
            //else
            //{
            //    objgcsj.GKLX = "3";
            //}

            if (objgcsj.GKLX == "1")
            {
                objgcsj.GKLX = "0";
            }
            else if (objgcsj.GKLX == "2" || objgcsj.GKLX == "3")
            {
                objgcsj.GKLX = "1";
            }
            else if (objgcsj.GKLX == "4")
            {
                objgcsj.GKLX = "2";
            }
            else
            {
                objgcsj.GKLX = "3";
            }

            var objyjsj = new 中科宇图.WT02()
            {
                jcsxh = objgcsj.imslsh.ToString(),
                gklx = objgcsj.GKLX.ToString(),
                hcclz = objgcsj.m_HCGCSJ.ToString(),
                coclz = objgcsj.m_COGCSJ.ToString("0.00"),
                noclz = objgcsj.m_NOGCSJ.ToString(),
                o2clz = objgcsj.m_O2GCSJ.ToString(),
                co2clz = objgcsj.m_CO2GCSJ.ToString(),
                cs = objgcsj.m_SpeedGCSJ.ToString(),
                glkqxs = objgcsj.m_LAMDAGCSJ.ToString("0.00"),
                hcxzz = objgcsj.m_HCGCSJxz.ToString(),
                coxzz = objgcsj.m_COGCSJxz.ToString("0.00"),
                noxzz = objgcsj.m_NOGCSJxz.ToString(),
                zs = objgcsj.m_TrunGCSJ.ToString(),
                nl = objgcsj.m_NLGCSJ.ToString("0.00"),
                dpcgjfz = objgcsj.m_PWGCSJ.ToString("0.00"),
                xsxzxs = objgcsj.m_DFGCSJ.ToString("0.00"),
                sdxzxs = objgcsj.m_KHGCSJ.ToString("0.00"),
                csgkzjzgl = objgcsj.m_PWGCSJ.ToString("0.00"),
                csgkjsgl = 1.ToString(),
                csgkzsgl = (objgcsj.m_PWGCSJ - 1).ToString(),
                wd = objgcsj.swendu.ToString(),
                qy = objgcsj.sdaqiyi.ToString(),
                sd = objgcsj.sshidu.ToString(),
                yw = objgcsj.m_fyw.ToString("0.00"),
                dqsjc = objgcsj.jcgcdysj
            };
            string svalue = JsonConvert.SerializeObject(objyjsj);
            string jieguo = getwebservice("WT02", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                //       MessageBox.Show(rb.err);
            }
            else
            {
            }
            return jieguo;

        }
        public override string zmgcsjsds(string businessId, model.SDS.SDSgcsjZM objgcsj)
        {
            //0-70%额定转速、1-高怠速准备、2-高怠速检测、3-怠速准备、4-怠速检测
//            0(70%额定转速),1(高怠速准
//备),2(高怠速检测),3(怠速
//准备),4(怠速检测)
            var objyjsj = new 中科宇图.SDS2()
            {
                jcsxh = objgcsj.imslsh.ToString(),
                gklx = objgcsj.GKLX,
                hccsgk = objgcsj.m_iHc.ToString("0.00"),
                cocsgk = objgcsj.m_fCo.ToString("0.00"),
                co2csgk = objgcsj.m_fCo2.ToString("0.00"),
                o2csgkfxy = objgcsj.m_fO2.ToString("0.00"),
                jyyw = objgcsj.m_fyw.ToString("0.00"),
                glkqxs = objgcsj.m_fLamda.ToString("0.00"),
                fdjzs = objgcsj.itrun.ToString(),
                wd = objgcsj.m_fWenDu.ToString(),
                sd = objgcsj.m_fShiDu.ToString(),
                qy = objgcsj.m_fYaLi.ToString(),
                dqsjc = objgcsj.jcgcdysj

            };
            string svalue = JsonConvert.SerializeObject(objyjsj);
            string jieguo = getwebservice("SDS02", svalue);
            return jieguo;
        }
//-------------增加
        public override string baocunclexxyj(string Sid)
        {
            string shphm = "";
            string shpzl = "";
            string sedgl = "";
            string sedzs = "";
            string sjzzl = "";
            string scllx = "";
            string sfobd = "";
            string sqlch = string.Format(@"select * from clxxex where clxxid={0} ", int.Parse(Sid));
            DataTable dt = objdb.GetTable(sqlch);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    shphm = dt.Rows[i]["cphm"].ToString().Trim();
                    shpzl = dt.Rows[i]["hplb"].ToString().Trim();
                    sedgl = dt.Rows[i]["edgl"].ToString().Trim();
                    sjzzl = dt.Rows[i]["jzzl"].ToString().Trim();
                    sedzs = dt.Rows[i]["edzs"].ToString().Trim();
                    sfobd = dt.Rows[i]["sfyobd"].ToString().Trim();
                }
                m_mainform.baocunCLXX(shphm, shpzl, sedgl, sedzs, sjzzl, "","");
                m_mainform.sfOBD = false;
                if (sfobd.Contains("1"))
                {
                    m_mainform.sfOBD = true;
                }
            }

            return "1";
        }

        public override string XXTZ(string body)//监控
        {
            var sxxtz = new 中科宇图.XXTZ()
            {
                ztbs = body,
                xxxx = "{}"
            };
            string svalue = JsonConvert.SerializeObject(sxxtz);
            string jieguo = getwebservice("XXTZ", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            return jieguo;

        }


        public override string OBDDJ()
        {
            JsonData value = new LitJson.JsonData();
            value["jczbh"] = m_mainform.stationCode;
            string svalue = value.ToJson();
            string jieguo = getwebservice("OBD6", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            return jieguo;
        }

        public override string OBDYQ()
        {
            JsonData value = new LitJson.JsonData();
            value["jczbh"] = m_mainform.stationCode;
            string svalue = value.ToJson();
            string jieguo = getwebservice("OBD5", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            return jieguo;
        }

        public override string BgAirHC()
        {
            var azj22 = new 中科宇图.ZJ22()
            {
                hjbjco = "0",
                hjbjno = "0",
                hjbjhc = "0",
                hccl = "0",
                dlljcjg = "1",
                lljylcjcjg = "1",
                jcjg = "0",
                jckssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                jcjssj = DateTime.Now.AddSeconds(15).ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(azj22);
            string jieguo = getwebservice("ZJ22", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            return rb.result.ToString();
        }

        public override string getobdid(string ahphm)
        {
            string syeid = "";
            string sql = string.Format(@"select *  from zkOBD where cphm='{0}'order by clxxid desc", ahphm);
            DataTable dt = objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    syeid = dt.Rows[i]["yewid"].ToString().Trim();

                }
            }

            return syeid;
        }

        public override string sendOBDGCSJ(string sjylsh, string stime, int simslsh)
        {
            var OBDGC = new 联网通信协议.中科宇图.OBD2()
            {
                jcsxh = string.Format("{0}", simslsh),
                jqmjdkd = m_mainform.OBD_jqmkd.Length < 1 ? "0" : m_mainform.OBD_jqmkd,
                jsfhz = m_mainform.OBD_fh.Length < 1 ? "0" : m_mainform.OBD_fh,
                qycgqxh = m_mainform.OBD_qycgqxh.Length < 1 ? "0" : m_mainform.OBD_qycgqxh,
                glkqxs = m_mainform.OBD_glkqxs.Length < 1 ? "0" : m_mainform.OBD_glkqxs,
                ymkd = m_mainform.OBD_ymkd.Length < 1 ? "0" : m_mainform.OBD_ymkd,
                cs = m_mainform.OBD_cs.Length < 1 ? "0" : m_mainform.OBD_cs,
                zs = m_mainform.OBD_fdjzs.Length < 1 ? "0" : m_mainform.OBD_fdjzs,
                jqyl = m_mainform.OBD_jqyl.Length < 1 ? "0" : m_mainform.OBD_jqyl,
                jql = m_mainform.OBD_jql.Length < 1 ? "0" : m_mainform.OBD_jql,
                fdjscgl = m_mainform.OBD_scgl.Length < 1 ? "0" : m_mainform.OBD_scgl,
                zyyl = m_mainform.OBD_zyyl.Length < 1 ? "0" : m_mainform.OBD_zyyl,
                hyl = m_mainform.OBD_hyl.Length < 1 ? "0" : m_mainform.OBD_hyl,
                dycgqnd = m_mainform.OBD_no.Length < 1 ? "0" : m_mainform.OBD_no,
                nspsl = m_mainform.OBD_nsbsl.Length < 1 ? "0" : m_mainform.OBD_nsbsl,
                pqwd = m_mainform.OBD_pqwd.Length < 1 ? "0" : m_mainform.OBD_pqwd,
                klpjqyc = m_mainform.OBD_klbjqyc.Length < 1 ? "0" : m_mainform.OBD_klbjqyc,
                egrkd = m_mainform.OBD_egrkd.Length < 1 ? "0" : m_mainform.OBD_egrkd,
                rypsyl = m_mainform.OBD_rypsyl.Length < 1 ? "0" : m_mainform.OBD_rypsyl,
                dqsjc = stime//DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
            };
            string svalue = JsonConvert.SerializeObject(OBDGC);
            string jieguo = getwebservice("OBD2", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                //           MessageBox.Show(rb.err);
            }
            else
            {
            }
            return rb.result.ToString();
        }
        public override string uploadhxjc(model.尾气自检.hxjc objhxjc)//日常滑行测试结束后提交滑行结果
        {
            DateTime sdate;
            DateTime.TryParse(objhxjc.dtBeginTime, out sdate);
            var azj01 = new 联网通信协议.中科宇图.ZJ01()
            {
                jsqsjzj = "1",
                yrsjq = objhxjc.dtBeginTime,
                yrsjz = sdate.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss"),
                jbgl = objhxjc.fDIW,
                gssd = "50",
                gsjzhxllsj =objhxjc.TheoretialTime40,
                gsjzhxsjsj =objhxjc.ActualTime40,
                gsjzhxgl = objhxjc.fPowerI,
                gsjzjsgl = objhxjc.fLossPW40,
                dssd ="30",
                dsjzhxllsj = objhxjc.TheoretialTime25,
                dsjzhxsjsj = objhxjc.ActualTime25,
                dsjzhxgl = objhxjc.fPowerI,
                dsjzjsgl = objhxjc.fLossPW25,
                jcjg = "1",
                jckssj = objhxjc.dtBeginTime,
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(azj01);
            string jieguo = getwebservice("ZJ01", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                //MessageBox.Show(rb.err);
            }
            else
            {
            }
            return rb.result.ToString();
        }

        public override string uploadzj(string tph, model.尾气自检.cyhxsj objxljc)//9.30	上报柴油车底盘测功机滑行检查记录表
        {

            string gshuaxll="";
            string gshuaxsj="";
            string dshuaxll="";
            string dshuaxsj="";

            if (tph.Contains("10"))
            {
                objxljc.IHP20ACDT90 = "0";
                objxljc.IHP20ACDT80 = "0";
                objxljc.IHP20ACDT70 = "0";
                objxljc.IHP20ACDT60 = "0";
                objxljc.IHP20ACDT50 = "0";
                objxljc.IHP20ACDT40 = "0";
                objxljc.IHP20ACDT30 = "0";
                objxljc.IHP20ACDT20 = "0";
                objxljc.IHP20CCDT90 = "0";
                objxljc.IHP20CCDT80 = "0";
                objxljc.IHP20CCDT70 = "0";
                objxljc.IHP20CCDT60 = "0";
                objxljc.IHP20CCDT50 = "0";
                objxljc.IHP20CCDT40 = "0";
                objxljc.IHP20CCDT30 = "0";
                objxljc.IHP20CCDT20 = "0";

                objxljc.IHP30ACDT90 = "0";
                objxljc.IHP30ACDT80 = "0";
                objxljc.IHP30ACDT70 = "0";
                objxljc.IHP30ACDT60 = "0";
                objxljc.IHP30ACDT50 = "0";
                objxljc.IHP30ACDT40 = "0";
                objxljc.IHP30ACDT30 = "0";
                objxljc.IHP30ACDT20 = "0";
                objxljc.IHP30CCDT90 = "0";
                objxljc.IHP30CCDT80 = "0";
                objxljc.IHP30CCDT70 = "0";
                objxljc.IHP30CCDT60 = "0";
                objxljc.IHP30CCDT50 = "0";
                objxljc.IHP30CCDT40 = "0";
                objxljc.IHP30CCDT30 = "0";
                objxljc.IHP30CCDT20 = "0";

                gshuaxll = objxljc.IHP10CCDT70;
                gshuaxsj = objxljc.IHP10ACDT70;
                dshuaxll = objxljc.IHP10CCDT50;
                dshuaxsj = objxljc.IHP10ACDT60;
            }

            if (tph.Contains("20"))
            {
                objxljc.IHP30ACDT90 = "0";
                objxljc.IHP30ACDT80 = "0";
                objxljc.IHP30ACDT70 = "0";
                objxljc.IHP30ACDT60 = "0";
                objxljc.IHP30ACDT50 = "0";
                objxljc.IHP30ACDT40 = "0";
                objxljc.IHP30ACDT30 = "0";
                objxljc.IHP30ACDT20 = "0";
                objxljc.IHP30CCDT90 = "0";
                objxljc.IHP30CCDT80 = "0";
                objxljc.IHP30CCDT70 = "0";
                objxljc.IHP30CCDT60 = "0";
                objxljc.IHP30CCDT50 = "0";
                objxljc.IHP30CCDT40 = "0";
                objxljc.IHP30CCDT30 = "0";
                objxljc.IHP30CCDT20 = "0";

                objxljc.IHP10ACDT90 = "0";
                objxljc.IHP10ACDT80 = "0";
                objxljc.IHP10ACDT70 = "0";
                objxljc.IHP10ACDT60 = "0";
                objxljc.IHP10ACDT50 = "0";
                objxljc.IHP10ACDT40 = "0";
                objxljc.IHP10ACDT30 = "0";
                objxljc.IHP10ACDT20 = "0";
                objxljc.IHP10CCDT90 = "0";
                objxljc.IHP10CCDT80 = "0";
                objxljc.IHP10CCDT70 = "0";
                objxljc.IHP10CCDT60 = "0";
                objxljc.IHP10CCDT50 = "0";
                objxljc.IHP10CCDT40 = "0";
                objxljc.IHP10CCDT30 = "0";
                objxljc.IHP10CCDT20 = "0";

                gshuaxll = objxljc.IHP20CCDT70;
                gshuaxsj = objxljc.IHP20ACDT70;
                dshuaxll = objxljc.IHP20CCDT50;
                dshuaxsj = objxljc.IHP20ACDT60;
            }

            if (tph.Contains("30"))
            {
                objxljc.IHP20ACDT90 = "0";
                objxljc.IHP20ACDT80 = "0";
                objxljc.IHP20ACDT70 = "0";
                objxljc.IHP20ACDT60 = "0";
                objxljc.IHP20ACDT50 = "0";
                objxljc.IHP20ACDT40 = "0";
                objxljc.IHP20ACDT30 = "0";
                objxljc.IHP20ACDT20 = "0";
                objxljc.IHP20CCDT90 = "0";
                objxljc.IHP20CCDT80 = "0";
                objxljc.IHP20CCDT70 = "0";
                objxljc.IHP20CCDT60 = "0";
                objxljc.IHP20CCDT50 = "0";
                objxljc.IHP20CCDT40 = "0";
                objxljc.IHP20CCDT30 = "0";
                objxljc.IHP20CCDT20 = "0";

                objxljc.IHP10ACDT90 = "0";
                objxljc.IHP10ACDT80 = "0";
                objxljc.IHP10ACDT70 = "0";
                objxljc.IHP10ACDT60 = "0";
                objxljc.IHP10ACDT50 = "0";
                objxljc.IHP10ACDT40 = "0";
                objxljc.IHP10ACDT30 = "0";
                objxljc.IHP10ACDT20 = "0";
                objxljc.IHP10CCDT90 = "0";
                objxljc.IHP10CCDT80 = "0";
                objxljc.IHP10CCDT70 = "0";
                objxljc.IHP10CCDT60 = "0";
                objxljc.IHP10CCDT50 = "0";
                objxljc.IHP10CCDT40 = "0";
                objxljc.IHP10CCDT30 = "0";
                objxljc.IHP10CCDT20 = "0";

                gshuaxll = objxljc.IHP30CCDT70;
                gshuaxsj = objxljc.IHP30ACDT70;
                dshuaxll = objxljc.IHP30CCDT50;
                dshuaxsj = objxljc.IHP30ACDT60;
            }

            DateTime sdate;
            DateTime.TryParse(objxljc.SlideTimeStart, out sdate);
            var azj01 = new 联网通信协议.中科宇图.ZJ01()
            {
                jsqsjzj = "1",
                yrsjq = objxljc.SlideTimeStart,
                yrsjz = sdate.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss"),
                jbgl = objxljc.DIW,
                gssd = "64",
                gsjzhxllsj = gshuaxll,
                gsjzhxsjsj = gshuaxsj,
                gsjzhxgl = tph,
                gsjzjsgl = objxljc.PLHP70,
                dssd = "48",
                dsjzhxllsj = dshuaxll,
                dsjzhxsjsj = dshuaxsj,
                dsjzhxgl = tph,
                dsjzjsgl = objxljc.PLHP50,
                jcjg = "1",
                jckssj = objxljc.SlideTimeStart,
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(azj01);
            string jieguo = getwebservice("ZJ01", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                //MessageBox.Show(rb.err);
            }
            else
            {
            }
            return rb.result.ToString();
        }

        public override string uploadzj(model.尾气自检.jsglv objjsglv)
        {
            var azj02 = new 联网通信协议.中科宇图.ZJ02()
            {
                sdqj1 = "24-16",
                mysd1 = "20",
                jsgl1 = objjsglv.jsgl4,
                sdqj2 = "34-26",
                mysd2 = "30",
                jsgl2 = objjsglv.jsgl3,
                sdqj3 = "44-36",
                mysd3 = "40",
                jsgl3 = objjsglv.jsgl2,
                sdqj4 = "54-46",
                mysd4 = "40",
                jsgl4 = objjsglv.jsgl1,
                zdsd = "54",
                jcjg = "1",
                jckssj = objjsglv.PLTimeStart1,
                jcjssj = objjsglv.SlideTimeEnd5
            };
            string svalue = JsonConvert.SerializeObject(azj02);
            string jieguo = getwebservice("ZJ02", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                //MessageBox.Show(rb.err);
            }
            else
            {
            }
            return rb.result.ToString();
        }
        public override string uploadjdli()
        {
            var azj03 = new 中科宇图.ZJ03()
            {
                sjl1 = "100",
                scl1 = "99",
                nl1wc = "1",
                sjl2 = "90",
                scl2 = "90",
                nl2wc = "0",
                sjl3 = "100",
                scl3 = "101",
                nl3wc = "-1",
                sjl4 = "200",
                scl4 = "200",
                nl4wc = "0",
                bdkssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                bdjssj = DateTime.Now.AddMilliseconds(30).ToString("yyyy-MM-dd HH:mm:ss"),
                jzjg = "1"
            };
            string svalue = JsonConvert.SerializeObject(azj03);
            string jieguo = getwebservice("ZJ03", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            return jieguo;
        }
        public override string uploadzj(model.尾气自检.fqyddjc objxljc)
        {
            string hege = "1";
            string qtlx = "1";
            if (objxljc.CheckTypeex.Contains("零气"))//1低标 4高标 2中低浓度 3中高浓度  0零气
            {
                qtlx = "0";
            }
            else if (objxljc.CheckTypeex.Contains("高标"))
            {
                qtlx = "4";
            }
            else if (objxljc.CheckTypeex.Contains("中低浓度"))
            {
                qtlx = "2";
            }
            else if (objxljc.CheckTypeex.Contains("中高浓度"))
            {
                qtlx = "3";
            }
            var azj23 = new 联网通信协议.中科宇图.ZJ23()
            {
                bqlb = qtlx,
                co2bqndz = objxljc.StdValCO2,
                co2scndz = objxljc.CheckValCO2,
                cobqndz = objxljc.StdValCO,
                coscndz = objxljc.CheckValCO,
                nobqndz = objxljc.StdValNO,
                noscndz = objxljc.CheckValNO,
                no2bqndz = "0",
                no2scndz = "0",
                hcbqndz = objxljc.StdValHC,
                hcscndz = objxljc.CheckValHC,
                o2bqndz = objxljc.StdValO2,
                o2scndz = objxljc.CheckValO2,
                mybwdlxs = objxljc.PEF,
                bqbwndz = objxljc.C3H8,
                jzjg = "1",
                jzkssj = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss"),
                jzjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svalue = JsonConvert.SerializeObject(azj23);
            string jieguo = getwebservice("ZJ23", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
/////////////////
            var azj21 = new 中科宇图.ZJ21()
            {
                mfxjcjg = "1",
                tl = "1",
                dlljcjg = "1",
                jckssj = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss"),
                jcjssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };
            string svaluefxy = JsonConvert.SerializeObject(azj21);
            string jieguofxy = getwebservice("ZJ21", svalue);
            RootObject rbfx = JsonConvert.DeserializeObject<RootObject>(jieguofxy);

            if (!rbfx.result.Contains("1"))
            {
                //MessageBox.Show(rbfx.err);
            }
            else
            {
            }
            return jieguo;
        
        }
        public override string uploadzj(model.尾气自检.btgydjjc objzjsj)//烟度校准 BD000 6
        {
            var azj31 = new 联网通信协议.中科宇图.ZJ31()
            {
                ldjc = "1",//零点检查
                lcjc = "1",//调零检查
                lgpz1 = objzjsj.StdVal30,
                lgpz2 = objzjsj.StdVal50,
                jcz1 = objzjsj.CheckVal30,
                jcz2 = objzjsj.CheckVal50,
                jcjg = "1",
                jckssj = DateTime.Now.ToString("yyyy-MM-dd 00:00:00"),
                jcjssj = DateTime.Now.AddSeconds(20).ToString("yyyy-MM-dd 00:00:00")
            };
            string svalue = JsonConvert.SerializeObject(azj31);
            string jieguo = getwebservice("ZJ31", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                //MessageBox.Show(rbfx.err);
            }
            else
            {
            }
            return jieguo;
        }
        public override string uploadzhuansu(string svalue)
        {
            string jieguo = getwebservice("ZJ41", svalue);
            RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);

            if (!rb.result.Contains("1"))
            {
                MessageBox.Show(rb.err);
            }
            else
            {
            }
            return jieguo;
        }
        public override string uploadzj(model.尾气自检.dzqxzzijian objxljc)//电子环境信息检查(ZJ000-08)
        { 
             var azj51 = new 联网通信协议.中科宇图.ZJ51()
                {
                    sjhjwd = objxljc.CheckTempVal,
                    clhjwd = objxljc.StdTempVal,
                    sjhjxdsd = objxljc.CheckHumiVal,
                    clhjxdsd = objxljc.StdHumiVal,
                    sjhjdqyl = objxljc.CheckPressVal,
                    clhjdqyl = objxljc.StdPressVal,
                    jckssj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    jcjssj = DateTime.Now.AddSeconds(10).ToString("yyyy-MM-dd HH:mm:ss")
                };
             string svalue = JsonConvert.SerializeObject(azj51);
             string jieguo = getwebservice("ZJ51", svalue);
             RootObject rb = JsonConvert.DeserializeObject<RootObject>(jieguo);
             if (!rb.result.Contains("1"))
             {
                 //MessageBox.Show(rbfx.err);
             }
             else
             {
             }
             return jieguo;
        }
        public override void luxiangkaishi(string sjylsh, string hphm, string hpzl, string stongdao, string gongwei)
        {
            if (stongdao.Length > 0)
            {
                string ssql = string.Format(@"select * from luxiangkaishi where jylsh='{0}' and gongwei='{1}' and jycs='{2}' ", sjylsh, gongwei, '1');
                if (objdb.selectDBcount(ssql) < 1)
                {
                    ssql = string.Format(@"insert into luxiangkaishi(jylsh,
                                                            jyjgbh,
                                                            hphm,
                                                            hpzl,
                                                            tongdao,
                                                            gongwei,
                                                            wancheng,
                                                            lxlj,
                                                            lxzm,
                                                            jycs) values(
                                                            '{0}',
                                                            '{1}',
                                                            '{2}',
                                                            '{3}',
                                                            '{4}',
                                                            '{5}',
                                                            '{6}',
                                                            '{7}',
                                                            '{8}',
                                                            '{9}')",
                                                                    sjylsh,
                                                                    m_mainform.organ,
                                                                    hphm,
                                                                    hpzl,
                                                                    stongdao,
                                                                    gongwei,
                                                                    "否",
                                                                    "",
                                                                    "",
                                                                    "1");
                }
                else
                {
                    ssql = string.Format(@"update  luxiangkaishi set jyjgbh='{0}',
                                                            hphm='{1}',
                                                            hpzl='{2}',
                                                            tongdao='{3}',
                                                            wancheng='{5}',
                                                            lxlj='{6}',
                                                            lxzm='{7}' where jylsh='{9}'   and gongwei='{4}' and jycs='{8}'",
                                                                    m_mainform.organ,
                                                                    hphm,
                                                                    hpzl,
                                                                    stongdao,
                                                                    gongwei,
                                                                    "否",
                                                                    "",
                                                                    "",
                                                                    "1",
                                                                    sjylsh);
                }
                objdb.InsertDB(ssql);
            }
        }

        public override void luxiangjieshu(string sjylsh, string stongdao, string gongwei)
        {
            string sqlrj;
            if (stongdao.Length > 0)
            {
                sqlrj = string.Format(@"insert into luxiangjieshu (
                                               jylsh,
                                                jyjgbh,
                                                hphm,
                                                hpzl,
                                                tongdao,
                                                gongwei,
                                                xuhao,
                                                wancheng,
                                                jycs) values ('{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}')",
                                                 sjylsh,
                                                 m_mainform.organ,
                                                 "",
                                                 "",
                                                 stongdao,
                                                 gongwei,
                                                 "",
                                                 "否",
                                                 "1");
                objdb.InsertDB(sqlrj);
            }
        }

        public override void zhuapai(string sjylsh, string hphm, string hpzl, string stongdao, string gongwei, string xuhao)
        {
            string ssql = "";
            if (stongdao.Length > 0)
            {
                ssql = string.Format(@"insert into xianneizhaopian (
                                               jylsh,
                                                jyjgbh,
                                                hphm,
                                                hpzl,
                                                tongdao,
                                                gongwei,
                                                xuhao,
                                                wancheng) values ('{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}')",
                                           sjylsh,
                                           m_mainform.organ,
                                           hphm,
                                           hpzl,
                                           stongdao,
                                           gongwei,
                                           "",
                                           "否");

                objdb.InsertDB(ssql);
            }
        
        }

    }
}
